package com.wm.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 消息发送实现，任何消息发送都由此类完成
 */

@Component
public class SysMesgSendService {

    @Autowired
    private SimpMessagingTemplate template;

    /**
     * webSocker消息发送
     * @param userId 用户id
     */
    public void sendSocketMsg(Long userId) {
        template.convertAndSend("/webSocketData/user/" + userId, "您接受了一条新的待办任务");
    }

    /**
     * webSocker消息发送
     * @param userIds 用户id集合
     */
    public void sendSocketMsg(List<Long> userIds) {
        if (!userIds.isEmpty()) {
            userIds.forEach(id -> {
                sendSocketMsg(id);
            });
        }
    }

}
